﻿using System;
using System.Messaging;
using System.Xml;
using System.Xml.Linq;

namespace MsmqView.Core.Messaging
{
	public class PlainXmlMessageFormatter : IMessageFormatter
	{
		#region IMessageFormatter Members

		public bool CanRead(Message message)
		{
			return true;
		}

		public object Read(Message message)
		{
			XmlTextReader xmlReader = new XmlTextReader(message.BodyStream)
			{
				WhitespaceHandling = WhitespaceHandling.Significant,
				ProhibitDtd = true
			};

			var xml = XDocument.Load(xmlReader);

			return xml.ToString();
		}

		public void Write(Message message, object obj)
		{
			throw new NotImplementedException();
		}

		#endregion

		#region ICloneable Members

		public object Clone()
		{
			throw new NotImplementedException();
		}

		#endregion
	}
}
